Hệ thống quản lý ISP trong PHP
1 <?php
2
3
4 /*
5 * We process the admin login form here
6 */
7
8 // Start from getting the hader which contains some settings we need
9 require_once 'includes/headx.php';
10
11
12 // require the admins class which containes most functions applied to admins
13 require_once "includes/classes/admin-class.php";
14
15 $admins = new Admins($dbh);
16
17 // Let's process the form now
18 // Starting by checking if the forme has been submitted
19 if (!isset($_POST) || sizeof($_POST) == 0 )
20 {
21 session::set('error', 'Submit the form first.');
22 $commons->redirectTo(SITE_PATH.'login.php');
23 }
24
25 // If the form is submitted, let's check if the fields are not empty
26 if ($commons->isFieldEmpty($_POST['username']) || $commons->isFieldEmpty($_POST['password']) )
27 {
28 session::set('error', 'All fields are required.');
29 $commons->redirectTo(SITE_PATH.'login.php');
30
31 }
32
33 // Now let's check if the the username and password match a line in our table
34
35 $user_name = htmlspecialchars( $_POST['username'], ENT_QUOTES, 'UTF-8' );
36 $user_pwd = htmlspecialchars( $_POST['password'], ENT_QUOTES, 'UTF-8' );
37
38 if (!$admins->loginAdmin($user_name, $user_pwd))
39 {
40 session::set('error', 'Cannot connect you. Check your credentials.');
41 $commons->redirectTo(SITE_PATH.'login.php');
42
43 }
44
45 // Otherwise we can set a session to the admin and send him to the dashboard
46 // The session will hold only the username.
47 session::set('admin_session', $user_name);
48 $commons->redirectTo(SITE_PATH.'index.php');